<?php

namespace App\Http\Controllers\Home;

use App\Models\HousePrice;
use App\Models\Navigation;
use App\Services\Home\IndexService;
use App\Services\Home\PropertyService;
use App\Traits\CommonData;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class IndexController extends Controller
{
    use CommonData;
    protected $service;
    protected $propertyService;

    public function __construct(IndexService $indexService,PropertyService $propertyService)
    {
        $this->service = $indexService;
        $this->propertyService = $propertyService;
    }

    public function getMenu()
    {
        $menu = Navigation::where('parent_id',0)->where('status','T')->orderBy('sort','asc')->get();
        return response()->json([
           'code' => 0,
           'menu' => $menu
        ]);
    }

    public function index()
    {
        // 获取热销楼盘
        $rec = $this->propertyService->getListByRecommend('h');
        return view(env('DEFAULT_TEMPLATE').'.index',compact('rec'));
    }

    public function getData(Request $request)
    {
        // 获取近6个月的月份及起始日期
//        $date = $this->getDateByDay(6);
        return $this->service->getDataByCity($request->input('city_id'));
    }

    public function getAverageData(Request $request)
    {
        return $this->service->getAverageData($request->input('city_id'));
    }


}
